package com.rover022.flixelgame.utils
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapEncodingColorSpace;
	import flash.geom.Rectangle;
	import flash.utils.ByteArray;

	public class BitMapTool
	{
		public function BitMapTool()
		{
		}

		/**
		 * 根据传入的2个jpg位图放回一个透明通道的 BitmapData
		 * @param soure 源 [BitmapData]
		 * @param mask  遮罩 [BitmapData]
		 *
		 */
		public function makeAlphaBitMap(soure:BitmapData, mask:BitmapData):BitmapData
		{
			var rect:Rectangle = new Rectangle(0, 0, mask.width, mask.height);
			var sourebuffer:ByteArray = soure.getPixels(rect);
			var maskbuffer:ByteArray = mask.getPixels(rect);
			var color:Number = 0xff * 3;
			sourebuffer.position = 0;
			for (var i:int = 0; i < maskbuffer.length; i += 4)
			{
				var whitenum:Number = (maskbuffer[i + 1] + maskbuffer[i + 2] + maskbuffer[i + 3]);
				if (whitenum != color)
				{
					sourebuffer[i] = whitenum / 3;
				}
			}
			var copysoure:BitmapData = new BitmapData(rect.width, rect.height); //建立一个带透明通道的图
			copysoure.setPixels(rect, sourebuffer);
			return copysoure;
			
			var s:Bitmap;
			var s
			
		}
	}
}
